

use shq_common::prelude::User;
// 登录处理函数
pub async fn login(user_no: &str, user_pwd: &str) -> anyhow::Result<(User,String)> {
    use jsonwebtoken::{encode, EncodingKey, Header};
    use shq_common::prelude::{get_app_config, Claims};
    let user=shq_pas_backend::user_login(user_no, user_pwd).await?;
    let app_conf=get_app_config();
    // 生成 JWT
    let expiration = chrono::Utc::now() + chrono::Duration::hours(app_conf.jwt.expire as i64);
    let claims = Claims {
        user_id: user.id,
        exp: expiration.timestamp() as usize,
    };
    let jwt_conf=&get_app_config().jwt;
    let token = encode(
        &Header::default(),
        &claims,
        &EncodingKey::from_secret(jwt_conf.secret.as_bytes()),
    )?;
    Ok((user,token))
}

